home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
comms
/
other
/
amarquee
/
examples
/
amarqueesocketdebug.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-25
|
4KB
|
139 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/AMarquee_protos.h>
#include <pragmas/AMarquee_pragmas.h>
#define ASYNC_CONNECT
struct Library * AMarqueeBase = NULL;
struct QSession * session = NULL;
/* Takes user input until blank line is typed */
void ProcessDebugCommands(struct QSession * session)
{
while(1)
{
char debugline[500] = "\0\0\0\0\0\0\0\0";
char * keyword, * data;
ULONG dataLen = 0L;
LONG res;
printf("Enter your debug command now: "); fflush(stdout);
gets(debugline);
keyword = &debugline[2];
if (data = strchr(keyword,'='))
{
*data = '\0'; /* terminate the keyword */
data++;
dataLen = strlen(data)+1;
}
else {
strcpy(keyword+strlen(keyword),"\n");
dataLen=strlen(keyword)+1;
}
switch((int)(debugline[0]))
{
case '\0': res=QGo(session,0L); break;
case 's': res=QSendRawOp(session, keyword, dataLen-1); break;
default: printf("Command code %c was not recognized.\n",debugline[0]); break;
}
printf("(Op result was %i)\n",res);
if (debugline[0] == '\0') return;
}
}
void CleanExit(void)
{
printf("\nCleaning up...\n");
if (session) QFreeSession(session); /* This MUST be done before we close the library! */
if (AMarqueeBase) CloseLibrary(AMarqueeBase);
printf("All done.\n");
}
/* Main program */
int main(int argc, char ** argv)
{
char * connectTo;
int port;
printf("Usage Note: AMarqueeSocketDebug [hostname=localhost] [port=7]\n");
atexit(CleanExit);
connectTo = (argc>1) ? argv[1] : "localhost";
port = (argc>2) ? atoi(argv[2]) : 7;
if ((AMarqueeBase = OpenLibrary("amarquee.library",49L)) == NULL)
{
printf("Couldn't open amarquee.library v49!\n");
exit(RETURN_ERROR);
}
printf("Connecting to %s:%i\n",connectTo, port);
#ifdef ASYNC_CONNECT
if ((session = QNewSocketSessionAsync(connectTo, port,NULL)) == NULL)
{
printf("Couldn't connect to server %s:%i\n",connectTo, port);
exit(RETURN_WARN);
}
#else
if ((session = QNewSocketSession(connectTo, port,NULL)) == NULL)
{
printf("Couldn't connect to server %s:%i\n",connectTo, port);
exit(RETURN_WARN);
}
#endif
printf("Connected to server %s:%i\n",connectTo, port);
printf("Commands are:\n");
printf("\n");
printf("s data Send data to the remote host\n");
printf("<enter> Send accumulated transactions (GO!!)\n");
printf("\n");
printf("Press CTRL-F to enter commands, or CTRL-C to quit\n");
while(1)
{
struct QMessage * qMsg;
ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C) | (SIGBREAKF_CTRL_F);
/* Wait for next message from the server */
signals = Wait(signals);
if (signals & (1L << session->qMsgPort->mp_SigBit))
{
while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
{
/* Handle message */
printf("Message %p recieved---------\n",qMsg);
printf("Status: %i (%s)\n", qMsg->qm_Status, QErrorName(qMsg->qm_Status));
printf("Error Line: %i\n", qMsg->qm_ErrorLine);
printf("Message ID: %i\n", qMsg->qm_ID);
printf("Path: [%s]\n", qMsg->qm_Path?qMsg->qm_Path:"<NULL>");
if (qMsg->qm_Data) {
char *gh=(char *)qMsg->qm_Data;
gh[qMsg->qm_DataLen-1]=0;
}
printf("Data: [%s](int=%i)\n", qMsg->qm_Data?qMsg->qm_Data:((UBYTE*)"<NULL>"),qMsg->qm_Data?(*((int*)qMsg->qm_Data)):0);
printf("DataLen: %lu\n", qMsg->qm_DataLen);
printf("ActualLen: %lu\n", qMsg->qm_ActualLen);
FreeQMessage(session, qMsg);
}
}
if (signals & SIGBREAKF_CTRL_F) ProcessDebugCommands(session);
if (signals & SIGBREAKF_CTRL_C) break; /* Quit if CTRL-C pressed */
}
/* CleanExit() called here! */
}